﻿using AutoMapper;
using MediatR;
using Traceability.APP.Application.Command.Pictures;
using Traceability.Damoin;
using Traceability.ErrorCode;
using Traceability.Infaseture;

namespace Traceability.APP.Application.CommandHadnLer.Pictures
{
    public class GetpictureCommandHandLer : IRequestHandler<GetpictureCommand, APIResult<List<Picture>>>
    {
        private readonly IBaseRepostiy<Picture> _picture;

        public GetpictureCommandHandLer(IBaseRepostiy<Picture> picture)
        {
            _picture = picture;

        }
        public async Task<APIResult<List<Picture>>> Handle(GetpictureCommand request, CancellationToken cancellationToken)
        {
            // 获取所有养殖信息
            var list = _picture.GetAll().Where(x => !x.IsDeleted);

            // 根据批次筛选
            list = list.Where(x => x.Batch == request.Batch&&x.TraceType==request.TraceType&&x.ImgType==request.ImgType);

            return new APIResult<List<Picture>>
            {
                Code = ResultCode.Ok,
                Data = list.ToList(),
                Message = "获取成功"
            };
        }
    }
}
